package com.mdl.springmvc.handler.handlers;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Desc
 * @Author madengling
 * @Time 2020/12/11 10:27
 */
@ControllerAdvice
public class SpringMvcTestExceptionHandler {
    private static Logger logger = Logger.getLogger(SpringMvcTestExceptionHandler.class);

    @ExceptionHandler({ArithmeticException.class})
    public ModelAndView handlerArithmeticException(Exception ex){
        logger.error("---> 出异常了："+ex);
        ModelAndView mv = new ModelAndView("error");
        mv.addObject("exception", ex);
        return mv;
    }
}
